import { defineConfig, loadEnv, searchForWorkspaceRoot } from 'vite';
import VueDevTools from 'vite-plugin-vue-devtools';

export default defineConfig(({ mode }) => {
  const { VITE_SYSTEM_TITLE } = loadEnv(mode, process.cwd());
  const { VITE_MAP_URL } = loadEnv(mode, process.cwd());

  return {
    define: {
      VITE_SYSTEM_TITLE: JSON.stringify(VITE_SYSTEM_TITLE),
      VITE_MAP_URL: JSON.stringify(VITE_MAP_URL),
    },
    server: {
      host: '0.0.0.0',
      proxy: {
        '/api': {
          // target: 'http://192.168.60.61:9632', //曾云华
          // target: 'http://192.168.50.84:9632', // 崔翔
          // target: 'http://172.16.200.4:9632',
          // target: 'http://192.168.60.66:9632', //谌仲
          // target: 'http://192.168.60.63:9632', //何一鸣
          // target: 'http://op.dev.boeyo.com',
          target: 'http://eap.dev.boeyo.com',
          changeOrigin: true,
        },
        '/dxmap': {
          target: 'http://eap.dev.boeyo.com',
          changeOrigin: true,
        },
        '/bimface': {
          target: 'https://api.bimface.com',
          changeOrigin: true,
          rewrite(path) {
            return path.replace(/^\/bimface/, '');
          },
        },
      },
      fs: {
        allow: [searchForWorkspaceRoot(process.cwd())],
      },
    },
    plugins: [VueDevTools()],
    optimizeDeps: {
      entries: ['./src/app.ts'],
      include: ['ant-design-vue', 'qs', 'nprogress', '@boeyo/portal'],
    },
  };
});
